package com.bysc.cmsservice.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bysc.cmsservice.client.JoinClient;
import com.bysc.cmsservice.controller.*;
import com.bysc.cmsservice.entity.CmsBanner;
import com.bysc.cmsservice.entity.CmsMember;
import com.bysc.cmsservice.entity.CmsTeacher;
import com.bysc.commonutils.Results;
import com.bysc.commonutils.vo.CmsActivity;
import com.bysc.commonutils.vo.DeptVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;


/*
*
* 旧软协官网接口

* */
//@RestController
//@RequestMapping("/cmsservice/api")
//@Api(tags = "首页api")
//@Slf4j
//public class CmsOlderApiController {
//
//    @Autowired
//    private CmsBannerController bannerController;
//    @Autowired
//    private CmsMemberController memberController;
//    @Autowired
//    private CmsTeacherController teacherController;
//    @Autowired
//    private ThreadPoolExecutor threadPoolExecutor;
//    @Autowired
//    private CmsAnnouncementController announcementController;
//    @Autowired
//    private CmsActivityController activityController;
//    @Autowired
//    private JoinClient joinClient;

//    @ApiOperation(value = "查询首页数据")
//    //@GetMapping("/getIndexAll")
//    public Results getBannerList() {
//        try {
//            // 异步获取轮播图列表
//            /*
//            * TODO  还没改动态查询
//            * */
//            CompletableFuture<List<CmsBanner>> bannerFuture = CompletableFuture.supplyAsync(() -> {
//                List<CmsBanner> banners = (List<CmsBanner>) bannerController.getBannerList("2").getData().get("bannerList");
//                return banners;
//            }, threadPoolExecutor);
//
//            // 异步获取会员列表
//            /*
//            * TODO  还没改动态查询
//            * */
//            CompletableFuture<List<CmsMember>> memberFuture = CompletableFuture.supplyAsync(() -> {
//                IPage<CmsMember> memberIPage = (IPage<CmsMember>) memberController.getMemberList(1, 8, null).getData().get("list");
//                return memberIPage.getRecords();
//            }, threadPoolExecutor);
//
//            // 异步获取教师列表
//            /*
//            TODO 还没改动态查询
//            * 新增根据clubId查询教师列表
//            * */
//            CompletableFuture<List<CmsTeacher>> teacherFuture = CompletableFuture.supplyAsync(() -> {
//                IPage<CmsTeacher> teacherIPage = (IPage<CmsTeacher>) teacherController.getTeacherList(1, 6, null).getData().get("list");
//                return teacherIPage.getRecords();
//            }, threadPoolExecutor);
//
//            // 异步获取活动列表
//            CompletableFuture<List<CmsActivity>> cmsActivityFuture = CompletableFuture.supplyAsync(() -> {
//                IPage<CmsActivity> teacherIPage = (IPage<CmsActivity>) activityController.getActivityList(1, 2, null,null).getData().get("list");
//                return teacherIPage.getRecords();
//            }, threadPoolExecutor);
//
//            // 异步获取部门信息列表
//            CompletableFuture<List<DeptVo>> deptFuture = CompletableFuture.supplyAsync(() -> {
//                List<DeptVo> depts = (List<DeptVo>) joinClient.getAllDeptInfo().getData().get("depts");
//                return depts;
//            }, threadPoolExecutor);
//
//            // 异步获取背景图片链接集合
//            CompletableFuture<List<String>> backgroundFuture = CompletableFuture.supplyAsync(() -> {
//                List<String> backgroundList = new ArrayList<>();
//                backgroundList.add("http://42.194.233.38:9000/banner/5398c8ad-4ebf-4008-9ecd-baa87fca43de-白云学院（软协人物背景图）.jpg");
//                backgroundList.add("http://42.194.233.38:9000/banner/6ea2446b-bec5-4e97-a83c-df51d0376cd0-白云学院首页大图.jpg");
//                backgroundList.add("http://42.194.233.38:9000/banner/544fe2af-c1ac-44ea-b263-209f06dece60-关于我们.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/19ea1902-723a-45d3-ac93-0223fc13e8ce-人物.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/a56560ce-f21a-42a4-b66d-653c763ef9a3-软协.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/1187cda4-0c40-4721-a742-b23e17af9b8f-校训1.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/a45e417a-6865-4a92-a666-cb04a611b801-校训2.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/1af68ca6-a820-42cc-a19a-ac032b51ca9f-蓝色字.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/b360c640-be1f-483e-8ef7-61d1af7aff79-白色字.png");
//                backgroundList.add("http://42.194.233.38:9000/banner/e0e919cc-4415-4423-9fc1-6b908c47ed88-活动背景图.png");
//                return backgroundList;
//            }, threadPoolExecutor);
//
//            // 等待所有异步任务完成
//            CompletableFuture.allOf(bannerFuture, memberFuture, teacherFuture, cmsActivityFuture, deptFuture, backgroundFuture).join();
//
//            // 获取结果
//            List<CmsBanner> banners = bannerFuture.get();
//            List<CmsMember> members = memberFuture.get();
//            List<CmsTeacher> teachers = teacherFuture.get();
//            List<CmsActivity> activities = cmsActivityFuture.get();
//            List<DeptVo> deptVos = deptFuture.get();
//            List<String> backgroundList = backgroundFuture.get();
//
//            return Results.ok()
//                    .data("bannerList", banners)
//                    .data("memberList", members)
//                    .data("teacherList", teachers)
//                    .data("activitieList", activities)
//                    .data("deptList", deptVos)
//                    .data("backgroundList", backgroundList);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Results.error();
//        }
//    }
//}
